package com.ganzalang.gmall.gmallfreemarker.common.api;

import com.fasterxml.jackson.databind.ser.Serializers;
import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResult<T> implements Serializable {

    private static final long serialVersionUID = -1797599388804211131L;
    private Integer code;

    private String msg;

    private T data;

    private static final Integer SUCCESS_CODE = 0;

    private static final String SUCCESS_MSG = "success";

    public BaseResult() {
    }

    public BaseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BaseResult<T> success(T data) {
        return new BaseResult<>(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static <T> BaseResult<T> success(String msg, T data) {
        return new BaseResult<>(SUCCESS_CODE, msg, data);
    }
}
